const fs = require("fs-extra");

async function transformRequest(url, server) {
  const { pluginContainer } = server;
  const { id } = await pluginContainer.resolveId(url);
  console.log("DDDDDDDDDDDDDdurl,", url, id);
  const loadResult = await pluginContainer.load(id);
  let code;
  if (loadResult) {
    code = loadResult.code;
  } else {
    code = await fs.readFile(id, "utf8");
  }

  const transformedResult = await pluginContainer.transform(code, id);
  return transformedResult;
}

module.exports = transformRequest;
